#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2019/6/12 9:53
# @Author  : khz_df
# @Site    : 
# @File    : foo_jiangziyang.py
# @Software: ce9nt


import os
import tensorflow as tf


def foo_capter3():
    a = tf.constant([1.0, 2.0], name='a')
    b = tf.constant([3.0, 4.0], name='b')
    result = a + b
    print(result)
    c = tf.constant([[3.0], [4.0]], name='c')
    c = tf.constant([3.0, 4.0], name='c')
    result = a * c
    print(result)
    print(a.graph is tf.get_default_graph())
    print(b.graph is tf.get_default_graph())

    g1 = tf.Graph()
    with g1.as_default():
        a = tf.get_variable('a', [2], initializer=tf.ones_initializer())

    with tf.Session() as sess:
        a = tf.get_variable('a', [2], initializer=tf.ones_initializer())
        sess.run(tf.initialize_all_variables())
        print(sess.run(result))
        print(tf.global_variables())
        print(tf.all_variables())


def foo_capter3_2():
    with tf.variable_scope('one'):
        a = tf.get_variable('var1', [1])
        print(a.name)
    # with tf.variable_scope('one'):
    #     a = tf.get_variable('var1', [1])
    #     print(a.name)
    # with tf.variable_scope('one', reuse=True):
    #     a = tf.get_variable('var1', [1])
    #     print(a.name)

    with tf.variable_scope('two'):
        a = tf.get_variable('var2', [1])
        print(a.name)

    with tf.name_scope('a'):
        a = tf.Variable([1], name='a')
        print(a.name)

        a = tf.get_variable('b', [1])
        print(a.name)

    with tf.name_scope('b'):            # , reuse=True
        c = tf.get_variable('b', [1])


def main():
    foo_capter3_2()


if __name__ == "__main__":
    print("------------------    Enter __main__    ------------------")

    print(u"[Current work directory is : ]\t" + os.getcwd())
    print(u"[Current process ID is : ]\t" + str(os.getpid()))
    print("\n")
    main()

    print("------------------    Leave __main__    ------------------")
